# -*- coding: utf-8 -*-
#(c)Jonathan & Gregoire (read __doc__ for more information)
#Copyright (C)%(author)s (%(date)s)
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

## @packagename pattern
# It is a collection of pattern object for implement MVC pattern design


from	engine.pattern.cards.Card1     import Card1
from	engine.pattern.cards.Card2     import Card2
from	engine.pattern.cards.Card3     import Card3
from	engine.pattern.cards.Card4     import Card4
from	engine.pattern.cards.Card5     import Card5
from	engine.pattern.cards.Card6     import Card6
from	engine.pattern.cards.Card7     import Card7
from	engine.pattern.cards.Card8     import Card8
from	engine.Singleton               import Singleton
import	random

__author__      = \
"""
Jonathan MERCIER <bioinfornatics at gmail.com >
Gregoire NAUDIN  <greg.naudin at gmail.com    >

"""
__version__     = "$Revision: 0.1 $"
__date__        = "$Date: 2009/23/09$"
__copyright__   = "Copyright (c) 2009 Jonathan MERCIER and Gregoire NAUDIN"
__license__     = "GPL v3 or under"
__name__        = "Talon.py"
__description__ = \
"""
Talon is a class for store a stock of card. The players take one card from talon and play.
"""

## Documentation for Talon class
# This class is the stock card (talon)
# It is used for control the game event such as create player,take a card, give a point to a player etc ...
# @note: This class can be instaciated several times, but all game object have the same state.
# @see: Singleton
class Talon(Singleton) :
    ## The constructor
    # @param self The pointer object
    def __init__(self,):
        self.__talon=[]
        self.__create()
        self.shuffle()
        
    ## Public method take_card
    # @param self The pointer object
    # @return a card object
    def take_card(self):
        return self.__talon.pop()

    ## Private method __create
    # @param self The pointer object
    def __create(self):
        ## 10 loop
        for i in range (1,11):
            item2 = Card2()
            item3 = Card3()
            item5 = Card5()
            item8 = Card8()
            ## Add card to talon
            for item in item2,item3,item5,item8:
                self.__talon.append(item)

        ## 5 loop
        for i in range (1,6):
            item1 = Card1()
            item4 = Card4()
            item6 = Card6()
            item7 = Card7()
            ## Add card to talon
            for item in item4,item6,item7,item1:
                self.__talon.append(item)

        ## remove one card type 1 because they are already one used for start the game
        self.__talon.pop()

    ## Public method shuffle
    # @param self: The pointer object
    def shuffle(self):
        ## shuffle list
        for i in range(random.randint(1,10)):
            random.shuffle(self.__talon)

    def left_card(self):
        return len(self.__talon)
